#define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
    vector<int> findAnagrams(string s, string p) {
        map<char, int> ms;
        map<char, int> mp;
        vector<int> v1;

        int n = p.size();
        int i = 0;
        while (n--)
        {
            ms[s[i]]++;
            mp[p[i]]++;
            i++;
        }
        for (int left = 0, right = i - 1; right < s.size();)
        {
            if (mp == ms)
            {
                v1.push_back(left);
                // for(auto num:ms)
                //     cout<<num.first<<num.second;
                // cout<<endl;
                // for(auto num:mp)
                //     cout<<num.first<<num.second;
            }
            if ((--ms[s[left]]) == 0)
                ms.erase(s[left]);
            left++;
            right++;
            // for(auto num:ms)
            //         cout<<num.first<<num.second;
            //     cout<<endl;
            ms[s[right]]++;
        }
        return v1;
    }
};